<template>
  <div class="app-container">

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" type="index" width="50"/>
      <el-table-column label="检查日期" align="center" prop="verifyPeoId">
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.verifyDate) }}</span>
          </template>
        </el-table-column>
      <el-table-column label="核查人" align="center" prop="verifyDeptId" />
      <el-table-column label="隐患名称" align="center" prop="verifyInfo" />
      <el-table-column label="隐患等级" align="center" prop="verifyDate" width="180">
      </el-table-column>
      <el-table-column label="所属单位" align="center" prop="rectificationLimit" width="180">
      </el-table-column>
      <el-table-column label="隐患描述" align="center" prop="rectificationMeasure" />
      <el-table-column label="验收责任单位" align="center" prop="rectificationDate" width="180">
      </el-table-column>
      <el-table-column label="整改人" align="center" prop="rectificationType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['biz:ht-hiddentroubleflow:update']">待下达</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 下达对话框-->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="隐患名称:" prop="state">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患等级:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患描述:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查类型:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患地点:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检查人:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属风险点:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属单位:" prop="level">
              <el-input v-model="form.htName" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改前图片:" prop="level">
              <img src="">
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="整改方式:" prop="level">
              <el-radio-group v-model="radio" @change="changeRadio">
                <el-radio label="立即整改">立即整改</el-radio>
                <el-radio label="限期整改">限期整改</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="showWay">
            <el-form-item label="整改期限:" prop="level">
              <el-date-picker style="width: 100%;" v-model="form.time" type="date" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改责任人" prop="checkPeoId2">
              <el-select style="width: 100%;" v-model="form.checkPeoId2" placeholder="请选择整改责任人">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改责任单位" prop="beCheckDeptId2">
              <el-select style="width: 100%;" v-model="form.beCheckDeptId2" placeholder="请选择整改责任单位">
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件:" prop="level">
              <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/"
                :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :limit="3"
                :on-exceed="handleExceed" :file-list="fileList">
                <i class="el-icon-upload" style="font-size: 40px;color:#67C23A;"></i>
                <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="整改措施:" prop="level">
              <el-input type="textarea" :rows="3" placeholder="请输入整改措施"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { createHtHiddentroubleflow, updateHtHiddentroubleflow, deleteHtHiddentroubleflow, getHtHiddentroubleflow, getHtHiddentroubleflowPage, exportHtHiddentroubleflowExcel } from "@/api/biz/htHiddentroubleflow";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listSimpleDepts} from "@/api/system/dept";
import {listSimpleUsers} from "@/api/system/user";
import FileUpload from '@/components/FileUpload';
export default {
  name: "HtHiddentroubleflow",
  components: {
    Treeselect
  },
  data() {
    return {
      radio:'',
      showWay:true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患流程信息列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        rectificationDeptId: null,
        rectificationPeoId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      // 执行查询
      getHtHiddentroubleflowPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
    },
    changeRadio(e) { //整改方式
      if (e == '立即整改') {
        this.showWay = false
      }else{
        this.showWay = true
      }
    },


    /** 下达按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.title = "隐患下达";
      this.open = true;
      // getHtHiddentroubleflow(id).then(response => {
      //   this.form = response.data;
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateHtHiddentroubleflow(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createHtHiddentroubleflow(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除隐患流程信息编号为"' + id + '"的数据项?').then(function() {
          return deleteHtHiddentroubleflow(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      // 执行导出
      this.$modal.confirm('是否确认导出所有隐患流程信息数据项?').then(() => {
          this.exportLoading = true;
          return exportHtHiddentroubleflowExcel(params);
        }).then(response => {
          this.$download.excel(response, '${table.classComment}.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style scoped>
  /deep/ .el-input--medium .el-input__inner {
    border: none;
  }

  /deep/.el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    border: 1px solid #e9e9e9;
    border-radius: 3px;
  }
  /deep/.el-select > .el-input{
    border: 1px solid #e9e9e9;
    border-radius: 3px;
  }
</style>
